﻿@{
    ViewBag.Title = "Index";
    var db = (ViewBag.Context as GNSystem.Models.DataContext);
    int i = 0;
    string cssClass;
}

<h2>Index</h2>


<table class="index_table float-left">
    <tr>
        <td colspan="2"><h3 class="float-left" style="margin-bottom: 10px; margin-left:10px; margin-top: 0px;">Forums</h3></td>
        <td colspan="2"><span class="float-right">@Html.ActionLink("Add a new forum", "AddForum")</span></td>
    </tr>
    <tr>
        <th>Id</th>
        <th>Name</th>
        <th>Desc.</th>
        <th># of Threads</th>
    </tr>
    @foreach (var forum in db.Forums.ToList())
    {cssClass = ((i++ % 2 != 0) ? "tr_odd" : "");
        
        <tr class="@cssClass">
            <td>@forum.ID</td>
            <td>@forum.ForumName</td>
            <td>@forum.Description</td>
            <td>
                @db.Threads.Count(t => t.ForumID == forum.ID)
            </td>
        </tr>
    }
</table>

<h3>Users</h3>
<table class="index_table">
    <tr>
        <th>Id</th>
        <th>Name</th>
        <th># of Threads</th>
    </tr>
    @foreach (var user in db.UserProfiles.ToList())
    {
        <tr>
            <td>@user.UserId</td>
            <td>@user.UserName</td>
            <td>@db.Threads.Count(t => t.UserID == user.UserId)</td>
        </tr>
    }
</table>
<table class="index_table">
    <tr>
        <th>Name</th>
        <th>Desc.</th>
        <th># of Threads</th>
    </tr>
    @foreach (var forum in db.Forums.ToList())
    {
        <tr>
            <td>@forum.ForumName</td>
            <td>@forum.Description</td>
            <td>
                @db.Threads.Count(t => t.ForumID == forum.ID)
            </td>
        </tr>
    }
</table>